//
//  ADJgSDKSplashAdContainer.m
//  AnyThinkSDKDemo
//
//  Created by 刘娟 on 2024/9/25.
//  Copyright © 2024 抽筋的灯. All rights reserved.
//

#import "ADJgSDKSplashAdContainer.h"

@interface ADJgSDKSplashAdContainer()<ADJgSDKSplashAdDelegate>

@property (nonatomic, strong) ADJgSDKSplashAd *splashAd;

@property (nonatomic, assign) CGFloat bidPrice;

@end

@implementation ADJgSDKSplashAdContainer
-(void)setDelegate:(id<ADJgSDKSplashAdDelegate>)delegate{
    self.splashAd.delegate = delegate;
}
// MARK: - Init
-(instancetype)initPosId:(NSString *)posId delegate:(id<ADJgSDKSplashAdDelegate>)delegate{
    self = [super init];
    if(self){
        self.splashAd = [ADJgSDKSplashAd new];
        self.splashAd.posId = posId;
        self.splashAd.delegate = delegate;
        self.splashAd.controller = [UIApplication sharedApplication].keyWindow.rootViewController;
        if (delegate == nil) {
            self.splashAd.delegate = self;
        }
    }
    return self;
}
- (void)loadAdWithBottomView:(UIView *)bottomView{
    [_splashAd loadAdInWindow:[UIApplication sharedApplication].keyWindow withBottomView:bottomView];
}
- (void)showAdInWindow:(UIWindow *)window{
    [_splashAd showAdInWindow:window];
}
- (void)loadAndShowInWindow:(UIWindow *)window withBottomView:(nullable UIView *)bottomView{
    [_splashAd loadAndShowInWindow:window withBottomView:bottomView];
}

-(void)close{
    _splashAd = nil;
}
- (NSInteger)getBidPrice{
    return _bidPrice;
}
#pragma mark -- ADJgSDKSplashAdDelegate

/**
 *  开屏广告素材加载成功
 */
- (void)adjg_splashAdSuccessToLoadAd:(ADJgSDKSplashAd *)splashAd{
#if DEBUG
        NSLog(@"ADJgSDK - 开屏广告 - 加载成功");
#endif
    ADJgSDKExtInfo *extInfo = [splashAd adjg_extInfo];
    _bidPrice = extInfo.ecpm.floatValue;
    if ([self.containerDelegate respondsToSelector:@selector(jgsdkContainer_jgsdkSplashAdDidLoad:withPrice:)]) {
        [self.containerDelegate jgsdkContainer_jgsdkSplashAdDidLoad:self withPrice:_bidPrice];
    }
}

/**
 *  开屏广告请求失败
 */
- (void)adjg_splashAdFailToPresentScreen:(ADJgSDKSplashAd *)splashAd failToPresentScreen:(ADJgAdapterErrorDefine *)error{
#if DEBUG
        NSLog(@"ADJgSDK - 开屏广告 - 加载失败：%@",error);
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgsdkContainer_jgsdkSplashAdFailLoadError:)]) {
        [self.containerDelegate jgsdkContainer_jgsdkSplashAdFailLoadError:nil];
    }
}
@end
